//
//  Status.swift
//  SinaBlog
//
//  Created by macs on 15/11/14.
//  Copyright © 2015年 BlackTail. All rights reserved.
//

import UIKit

class Status: NSObject {
    //微博创建时间
    var created_at : String?
    //时间
    var created_date : String? {
        
        if let dateString = created_at {
            return  NSDate.dateFromString(dateString)?.sinaComDate()
        }
        
        return nil
    }
    
    //微博ID
    var id : Int = 0
    //微博信息内容
    var text : String?
    
    
    //微博来源
    var source : String?
    //问哦波来源
    var sourceRegul : String? {
        
        if let  sour = retweeteds?.source {
            return sour.getSourceString().souceString
        }
        
        if let sour = source {
            
            return sour.getSourceString().souceString
        }
        
        return nil
    }
    
    //用户信息
    var user : Users?
    //微博的
    var since_id : Int = 0
    //
    var max_id : Int = 0
    
    //获得转发微博数据模型
    var retweeteds : Status?
    
    //图片urlString数组
    var pic_urls : [[String : AnyObject]]?
    //图片 url 计算属性
    var pictureUrl : [NSURL]? {
        
        guard let urls = pic_urls else{
            return nil
        }
        var urlArray = [NSURL]()
        for urlDict in urls {
            
            let url = NSURL(string: urlDict["thumbnail_pic"]! as! String);
            urlArray.append(url!)
        }
        return urlArray
    }
    
    var danzhangPicUrl : [NSURL]? {
        
        if retweeteds?.pictureUrl?.count > 0 {
            
            return retweeteds?.pictureUrl
        }
        
        return pictureUrl
    }
    
    init(dict:[String : AnyObject]) {
        
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
        //初始化用户模型数据
            user = Users(dict: value! as! [String : AnyObject])
            return
        }
        
        if key == "retweeted_status" {
            retweeteds = Status.init(dict: value as! [String : AnyObject])
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
